<template>
	<view>
		<!-- 		<view class="head">
			<view class="head-top">模板页面</view>
		</view> -->
		<view class="cont">
			<view class="item" v-for="(item,index) in list" :key="index">
				<image :src="item.url" class="img" lazy-load @click="view(item.url)"></image>
				<view class="item-bom">
					<view class="user-box">
						<image :src="item.avatarUrl" class="avatar"></image>
						<view class="name">{{item.nickName}}</view>
					</view>
					<view class="item-time">{{item.time | formatDate}}</view>
					<image v-if="role==3" src="../../static/images/icon/del1.png" class="icon" @click.stop="del(item)">
					</image>
				</view>
			</view>
		</view>
		<image v-if="show" src="../../static/images/icon/shua.png" class="shua" @click="shua"></image>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				list: [],
				show: true,
				role: 1,
				page: 1,
			}
		},
		computed: {},
		watch: {},
		methods: {
			view(e) {
				console.log(e)
				wx.previewImage({
					urls: [e],
					showmenu: true,
				})
			},
			getInfo() {
				let info = uni.getStorageSync('userInfo')
				this.role = info.role
			},
			getList() {
				uni.showLoading({
					title: '加载中'
				})
				const db = wx.cloud.database()

				// db.collection('order_ai').where({
				// 	isGallery: true
				// }).orderBy('time', 'desc').get().then(res => {
				// 	let infoObj = res.data
				// 	this.list = infoObj
				// 	uni.hideLoading()
				// })


				let list0 = this.list
				let skip = 8
				db.collection('order_ai').where({
					isGallery: true
				}).orderBy('time', 'desc').skip(skip * (this.page - 1)).limit(skip).get().then(res => {
					let list = res.data
					let list1 = list0.concat(list)
					this.list = list1
					uni.hideLoading()
				})

			},
			shua() {
				this.list = []
				this.page = 1
				this.getList()
				this.show = false
				setTimeout(() => {
					this.show = true
				}, 5000)
			},
			del(e) {
				console.log(e)
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认删除本条绘画',
					success: function(res) {
						if (res.confirm) {
							wx.cloud.callFunction({
								name: 'orderDel',
								data: {
									_id: e._id,
									url: e.url
								}
							}).then(() => {
								that.shua()
							})
						} else if (res.cancel) {}
					}
				})

			},
		},
		onLoad(options) {
			this.getList()
			this.getInfo()
		},
		onShow() {
			// this.list = []
			// this.page = 1
			// this.getList()
		},
		onReady() {},
		onPullDownRefresh() {
			this.shua()
		},
		onReachBottom() {
			this.page += 1
			this.getList()
		},
		onShareAppMessage() {
			return {
				title: '啊吧卡牌',
				path: '/pages/index/index',
			}
		},
		onPageScroll() {},

	}
</script>

<style lang="scss" scoped>
	.head {
		background-color: #fff;

		.head-top {
			font-size: 30rpx;
			text-align: center;
			color: red;
		}
	}

	.cont {
		width: 690rpx;
		margin-left: 30rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding-bottom: 50rpx;

		.item {
			// width: 320rpx;
			background-color: #fff;
			border-radius: 10rpx;
			margin-top: 20rpx;
			text-align: center;
			padding: 10rpx;
			box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.3);

			.img {
				width: 300rpx;
				height: 400rpx;
			}

			.item-bom {
				position: relative;

				.user-box {
					display: flex;
					align-items: center;

					.avatar {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						margin-left: 20rpx;
					}

					.name {
						font-size: 26rpx;
						margin-left: 10rpx;
					}
				}

				.item-time {
					font-size: 20rpx;
					margin-top: 10rpx;
					text-align: left;
					margin-left: 20rpx;
				}

				.icon {
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					right: 10rpx;
					bottom: 10rpx;
				}
			}



		}
	}

	.shua {
		position: fixed;
		right: 60rpx;
		bottom: 160rpx;
		width: 80rpx;
		height: 80rpx;

	}
</style>
